package com.xncoding.design.observation.demo;
/**
 * 生产者
 * @author Administrator
 */
public class Producer extends Thread {
	private String name;
	private Storage s=null;
	
	public Producer(String name,Storage s){
		this.name=name;
		this.s=s;
	}

	@Override
	public void run() {
	    try{
	    	while(true){
	    		if(s.getWorkQueue().isEmpty()){//工作完成
	    			break;
	    		}
	    	    Product product=s.getWorkQueue().poll();
	    	    if(product==null){
	    	    	continue;
	    	    }
	    		s.push(product);
	    	}
		}catch(InterruptedException e1){
			System.out.println(name+":异常");
			
		}finally{
			System.out.println(name+":完成工作");
		}
		

	}
	


}
